package hairmember

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/hairmember"
    hairmemberReq "github.com/flipped-aurora/gin-vue-admin/server/model/hairmember/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type ProjectTypesApi struct {}



// CreateProjectTypes 创建projectTypes表
// @Tags ProjectTypes
// @Summary 创建projectTypes表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body hairmember.ProjectTypes true "创建projectTypes表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /projectTypes/createProjectTypes [post]
func (projectTypesApi *ProjectTypesApi) CreateProjectTypes(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var projectTypes hairmember.ProjectTypes
	err := c.ShouldBindJSON(&projectTypes)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = projectTypesService.CreateProjectTypes(ctx,&projectTypes)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteProjectTypes 删除projectTypes表
// @Tags ProjectTypes
// @Summary 删除projectTypes表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body hairmember.ProjectTypes true "删除projectTypes表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /projectTypes/deleteProjectTypes [delete]
func (projectTypesApi *ProjectTypesApi) DeleteProjectTypes(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	id := c.Query("id")
	err := projectTypesService.DeleteProjectTypes(ctx,id)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteProjectTypesByIds 批量删除projectTypes表
// @Tags ProjectTypes
// @Summary 批量删除projectTypes表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /projectTypes/deleteProjectTypesByIds [delete]
func (projectTypesApi *ProjectTypesApi) DeleteProjectTypesByIds(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	ids := c.QueryArray("ids[]")
	err := projectTypesService.DeleteProjectTypesByIds(ctx,ids)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateProjectTypes 更新projectTypes表
// @Tags ProjectTypes
// @Summary 更新projectTypes表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body hairmember.ProjectTypes true "更新projectTypes表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /projectTypes/updateProjectTypes [put]
func (projectTypesApi *ProjectTypesApi) UpdateProjectTypes(c *gin.Context) {
    // 从ctx获取标准context进行业务行为
    ctx := c.Request.Context()

	var projectTypes hairmember.ProjectTypes
	err := c.ShouldBindJSON(&projectTypes)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = projectTypesService.UpdateProjectTypes(ctx,projectTypes)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindProjectTypes 用id查询projectTypes表
// @Tags ProjectTypes
// @Summary 用id查询projectTypes表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param id query int true "用id查询projectTypes表"
// @Success 200 {object} response.Response{data=hairmember.ProjectTypes,msg=string} "查询成功"
// @Router /projectTypes/findProjectTypes [get]
func (projectTypesApi *ProjectTypesApi) FindProjectTypes(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	id := c.Query("id")
	reprojectTypes, err := projectTypesService.GetProjectTypes(ctx,id)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(reprojectTypes, c)
}
// GetProjectTypesList 分页获取projectTypes表列表
// @Tags ProjectTypes
// @Summary 分页获取projectTypes表列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query hairmemberReq.ProjectTypesSearch true "分页获取projectTypes表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /projectTypes/getProjectTypesList [get]
func (projectTypesApi *ProjectTypesApi) GetProjectTypesList(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var pageInfo hairmemberReq.ProjectTypesSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := projectTypesService.GetProjectTypesInfoList(ctx,pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetProjectTypesPublic 不需要鉴权的projectTypes表接口 - 获取所有项目类型
// @Tags ProjectTypes
// @Summary 不需要鉴权的projectTypes表接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=[]hairmember.ProjectTypes,msg=string} "获取成功"
// @Router /projectTypes/getProjectTypesPublic [get]
func (projectTypesApi *ProjectTypesApi) GetProjectTypesPublic(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

    // 此接口不需要鉴权
    list, err := projectTypesService.GetProjectTypesPublic(ctx)
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取项目类型失败: " + err.Error(), c)
        return
    }
    response.OkWithDetailed(list, "获取项目类型成功", c)
}
